package com.yinxin.reflection;

import java.awt.*;

/**
 * @author yinxin
 * @Title:
 * @Package
 * @Description:
 * @date 2022/1/1110:49
 */
public class TestReflection {
    public static void main(String[] args) throws ClassNotFoundException {
//        Class<?> c1 = Class.forName("com.yinxin.reflection.Person");
//        Class<?> c2 = Class.forName("com.yinxin.reflection.Person");
//        Class<?> c3 = Class.forName("com.yinxin.reflection.Person");
//        System.out.println(c1.hashCode());
//        System.out.println(c2.hashCode());
//        System.out.println(c3.hashCode());
//===================================================================================
        Person person = new Student();
        System.out.println("这个人是："+person.name);

        //方式一：通过对象获得
        Class c1 = person.getClass();
        System.out.println(c1);

        //方式二：forname获得
        Class c2 = Class.forName("com.yinxin.reflection.Student");
        System.out.println(c2);

        //方式三：通过类名.class获得
        Class c3 = Student.class;
        System.out.println(c3);

        //方式四：基本内置类型的包装类都有一个Type属性
        Class integerClass = Integer.TYPE;
        System.out.println(integerClass);

        //获得父类类型
        Class c1Superclass = c1.getSuperclass();
        System.out.println(c1Superclass);

    }
}

//实体类
class Person{
    String name;
    int age;
    String gander;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGander() {
        return gander;
    }

    public void setGander(String gander) {
        this.gander = gander;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gander='" + gander + '\'' +
                '}';
    }
}

class Student extends Person{
    public Student() {
        this.name="学生";
    }
}

class Teacher extends Person{
    public Teacher() {
        this.name="老师";
    }
}